/**
 * 招聘需求编辑
 */
import React from 'react';
import { history, connect } from 'umi'
import AuthComponent from '@/utils/auth/AuthComponent';
import { eventTrack } from '@/utils/track';

import { Icon } from '../components';

function DemandEdit({ data = {}, user, button }) {
    const { employeeCode } = user;
    const { recruitCode, recruitStatus, principalEmployeeCode, launchEmployeeCode } = data;
    const showEdit = [principalEmployeeCode, launchEmployeeCode].includes(employeeCode);
    if (![2, 3].includes(recruitStatus) || !showEdit) {
        return null;
    }
    return (
        <AuthComponent code="office:recruitment:course:requirement:edit">
            <Icon
                button={button}
                title="编辑"
                type="listfunction_edit_icon_default"
                onClick={() => {
                    eventTrack({
                        eventName: 'personnel_management_recruitment_demand_list_detail_edit_click',
                        pageName: 'personnel_management_recruitment',
                        eventProps: {
                            click_context: data.dutyName
                        }
                    });
                    history.push({
                        pathname: '/office/personnelManagement/recruitment/demand/edit',
                        query: {
                            recruitCode
                        }
                    });
                }}
            />
        </AuthComponent>
    );
}

export default connect(({ user }) => ({ user: user.currentUser }))(DemandEdit);
